home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware City / Developers / Oberon⁄F / System / Docu / Stores (.txt) < prev    next >
Encoding:
Oberon Document  |  1994-06-07  |  22.4 KB  |  386 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Geneva
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Geneva
  22. HostPictures.StdViewDesc
  23. Geneva
  24. Dialog
  25. Views
  26. Files
  27. Ports
  28. Domains
  29. Fonts
  30. Stores
  31. Models
  32. Controllers
  33. Geneva
  34. Geneva
  35. 5.4 Stores
  36. DEFINITION Stores;
  37.     IMPORT Domains, Files;
  38.     CONST
  39.         alienVersion = 1; alienComponent = 2;
  40.         inconsistentVersion = -1; inconsistentType = -2; moduleFileNotFound = -3;
  41.         invalidModuleFile = -4; inconsModuleVersion = -5; typeNotFound = -6;
  42.     TYPE
  43.         LONGCHAR = INTEGER;
  44.         TypeName = ARRAY 64 OF CHAR;
  45.         TypePath = ARRAY 16 OF TypeName;
  46.         Store = POINTER TO StoreDesc;
  47.         StoreDesc = RECORD
  48.             init-: BOOLEAN;
  49.             PROCEDURE (s: Store) Clone (): Store;
  50.             PROCEDURE (s: Store) Init;
  51.             PROCEDURE (s: Store) InitDomain (d; Domains.Domain);
  52.             PROCEDURE (s: Store) Internalize (VAR rd: Reader);
  53.             PROCEDURE (s: Store) Externalize (VAR wr: Writer)
  54.         END;
  55.         Elem = POINTER TO ElemDesc;
  56.         ElemDesc = RECORD (StoreDesc)
  57.             domain-: Domains.Domain
  58.         END;
  59.         Reader = RECORD
  60.             rider-: Files.Reader;
  61.             cancelled-: BOOLEAN;
  62.             readAlien-: BOOLEAN;
  63.             PROCEDURE (VAR rd: Reader) ConnectTo (f: Files.File);
  64.             PROCEDURE (VAR rd: Reader) Pos (): LONGINT;
  65.             PROCEDURE (VAR rd: Reader) SetPos (pos: LONGINT);
  66.             PROCEDURE (VAR rd: Reader) ReadBool (VAR x: BOOLEAN);
  67.             PROCEDURE (VAR rd: Reader) ReadChar (VAR x: CHAR);
  68.             PROCEDURE (VAR rd: Reader) ReadLChar (VAR x: LONGCHAR);
  69.             PROCEDURE (VAR rd: Reader) ReadSInt (VAR x: SHORTINT);
  70.             PROCEDURE (VAR rd: Reader) ReadInt (VAR x: INTEGER);
  71.             PROCEDURE (VAR rd: Reader) ReadLInt (VAR x: LONGINT);
  72.             PROCEDURE (VAR rd: Reader) ReadReal (VAR x: REAL);
  73.             PROCEDURE (VAR rd: Reader) ReadLReal (VAR x: LONGREAL);
  74.             PROCEDURE (VAR rd: Reader) ReadSet (VAR x: SET);
  75.             PROCEDURE (VAR rd: Reader) ReadString (VAR x: ARRAY OF CHAR);
  76.             PROCEDURE (VAR rd: Reader) ReadLString (VAR x: ARRAY OF LONGCHAR);
  77.             PROCEDURE (VAR rd: Reader) ReadStore (VAR x: Store);
  78.             PROCEDURE (VAR rd: Reader) ReadVersion (min, max: SHORTINT; VAR version: SHORTINT);
  79.             PROCEDURE (VAR rd: Reader) TurnIntoAlien (cause: LONGINT)
  80.         END;
  81.         Writer = RECORD
  82.             rider-: Files.Writer;
  83.             PROCEDURE (VAR wr: Writer) ConnectTo (f: Files.File);
  84.             PROCEDURE (VAR wr: Writer) Pos (): LONGINT;
  85.             PROCEDURE (VAR wr: Writer) SetPos (pos: LONGINT);
  86.             PROCEDURE (VAR wr: Writer) WriteBool (x: BOOLEAN);
  87.             PROCEDURE (VAR wr: Writer) WriteChar (x: CHAR);
  88.             PROCEDURE (VAR wr: Writer) WriteLChar (x: LONGCHAR);
  89.             PROCEDURE (VAR wr: Writer) WriteSInt (x: SHORTINT);
  90.             PROCEDURE (VAR wr: Writer) WriteInt (x: INTEGER);
  91.             PROCEDURE (VAR wr: Writer) WriteLInt (x: LONGINT);
  92.             PROCEDURE (VAR wr: Writer) WriteReal (x: REAL);
  93.             PROCEDURE (VAR wr: Writer) WriteLReal (x: LONGREAL);
  94.             PROCEDURE (VAR wr: Writer) WriteSet (x: SET);
  95.             PROCEDURE (VAR wr: Writer) WriteString (x: ARRAY OF CHAR);
  96.             PROCEDURE (VAR wr: Writer) WriteLString (x: ARRAY OF LONGCHAR);
  97.             PROCEDURE (VAR wr: Writer) WriteStore (x: Store);
  98.             PROCEDURE (VAR wr: Writer) WriteVersion (version: SHORTINT)
  99.         END;
  100.         AlienComp = POINTER TO AlienCompDesc;
  101.         AlienCompDesc = RECORD
  102.             next-: AlienComp
  103.         END;
  104.         Alien = POINTER TO AlienDesc;
  105.         AlienDesc = RECORD (StoreDesc)
  106.             path-: TypePath;
  107.             cause-: LONGINT;
  108.             file-: Files.File;
  109.             comps-: AlienComp
  110.         END;
  111.         AlienElem = POINTER TO AlienElemDesc;
  112.         AlienElemDesc = RECORD (ElemDesc)
  113.             path-: TypePath;
  114.             cause-: LONGINT;
  115.             file-: Files.File;
  116.             comps-: AlienComp
  117.         END;
  118.         AlienPart = POINTER TO AlienPartDesc;
  119.         AlienPartDesc = RECORD (AlienCompDesc)
  120.             store-: Store
  121.         END;
  122.         AlienPiece = POINTER TO AlienPieceDesc;
  123.         AlienPieceDesc = RECORD (AlienCompDesc)
  124.             pos-, len-: LONGINT
  125.         END;
  126.     VAR ReportMsg: PROCEDURE (msg, p0, p1, p2: ARRAY OF CHAR);
  127.     PROCEDURE Clone (s: Store): Store;
  128.     PROCEDURE New (type: TypeName): Store;
  129.     PROCEDURE GetTypeName (s: Store; VAR type: TypeName);
  130.     PROCEDURE Report (msg, p0, p1, p2: ARRAY OF CHAR);
  131. END Stores.
  132. Module Stores defines a data type Store, which should be used as base type of all storable extensible objects. When storing an object of an extensible type, it is necessary to store not only its contents but also its particular type. A variable of (an extension of) type Store is stored in a file. A store must implement the Internalize procedure which takes a Reader as parameter, and the Externalize procedure which takes a Writer as parameter. Readers and writers are mappers on files. The types Views.View and TextModels.Model are examples of Store extensions.
  133. The contents of a store is stored in a file. When reading the same file by another Oberon configuration, it may occur that not all necessary modules are available in this configuration, i.e. the module which defines the store's type cannot be loaded. Yet reading such an "alien" store does not fail completely. Instead of the correct store type, an "alien" object is generated. Obviously such an alien cannot interpret the data it represents, and therefore cannot provide any special behavior. However, it may be copied and stored into another file, such that its contents on the new file are intact and consistent.
  134. Elements are special stores which belong to a particular domain (-> 5.1 "Domains"). The elements of a domain can be externalized and internalized such that pointers among them are reconstructed correctly upon internalization. In particular, alias pointers are handled correctly: if several elements point to another element of the same domain, this element is read in only once, and all the pointers to it are rebuilt. Arbitrary graphs can be handled this way. Links to elements of other domains are severed, i.e. become NIL upon internalization. Pointers to non-element stores yield the store again, but alias pointers are not handled: if several elements (or stores) point to a store, internalization creates one new store per pointer, such that each element gets its own independent instance of the store.
  135. Stores provides a pair of mapper types, which are used as parameters in a store's Internalize and Externalize procedures. These readers/writers use the following external (little endian) format:
  136. BOOLEAN
  137.     1 byte (0 = FALSE, 1 = TRUE)
  138.     1 byte in the Latin-1 character set (i.e. Unicode page 0; 00X..0FFX)
  139. LONGCHAR
  140.     2 byte in the Unicode character set (0000H..0FFFFH)
  141. SHORTINT
  142.     1 byte (-128..127)
  143. INTEGER
  144.     2 bytes (-32768..32767)
  145. LONGINT
  146.     4 bytes (-2147483648..2147483647)
  147.     4 bytes IEEE format
  148. LONGREAL
  149.     8 bytes IEEE format
  150.     4 bytes (least significant bit = element 0)
  151. String
  152.     string in the Latin-1 character set, followed by a 00X
  153. Long String
  154.     string in the Unicode character set, followed by a 0000H
  155. CONST alienVersion
  156. This value is assigned to a Reader's cause field if Reader.ReadVersion read a version outside of the specified range.
  157. CONST alienComponent
  158. This value can be used as cause parameter to Reader.TurnIntoAlien to indicate that the store itself could be read, but that some store contained in it is an alien. As an example, a view may turn itself into an alien if its model is an alien.
  159. CONST inconsistentVersion
  160. This value is assigned to a Reader's cause field if Reader.ReadVersion read a data block which has an inconsistent length, i.e. not all of its data have been read, or it has been attempted to read beyond the end of the data.
  161. CONST inconsistentType
  162. This value is assigned to a Reader's cause field if Reader.ReadVersion detected a change in the type extension hierarchy of the internalized type.
  163. CONST moduleFileNotFound
  164. This value is assigned to a Reader's cause field if Reader.ReadVersion tried to load a module defining an internalized type, and the codefile for this module couldn't be found.
  165. CONST invalidModuleFile
  166. This value is assigned to a Reader's cause field if Reader.ReadVersion tried to load a module defining an internalized type, and the module couldn't be loaded because it imports another module which cannot be loaded for some reason.
  167. CONST inconsModuleVersion
  168. This value is assigned to a Reader's cause field if Reader.ReadVersion tried to load a module defining an internalized type, and the module couldn't be loaded because its version is inconsistent with some already loaded module.
  169. CONST typeNotFound
  170. This value is assigned to a Reader's cause field if Reader.ReadVersion tried to internalize a non-existing type (the module was found, however).
  171. TYPE LONGCHAR
  172. Type for 2-byte characters in the Unicode character set.
  173. TYPE TypeName
  174. String type for the type name of an object.
  175. TYPE TypePath
  176. Array of type names.
  177. TYPE Store
  178. Interface
  179. Storable extensible data types like Views.View or TextModels.Text are derived from Store.
  180. Stores are allocated by suitable directories, e.g. Views.Directory or TextModels.Directory.
  181. Stores are used as base types for all extensible and persistent objects.
  182. init-: BOOLEAN
  183. This flag indicates whether a store's basic initialization steps have been performed already. Once set, it cannot be cleared anymore.
  184. Internalize asserts that the internalized store is not initialized, and then marks it as initialized.
  185. Externalize asserts that the externalized store is already initialized.
  186. A copy procedure typically asserts that the source is already initialized and that the destination is not yet initialized, and then marks it as initialized.
  187. A directory's allocation function returns an initialized store.
  188. Other initializations (e.g. assigning other store fields in an extension) may (but need not) be guarded by ~init, other operations may only be legal if init.
  189. PROCEDURE (s: Store) Clone (): Store
  190. Default
  191. Clone allocates a new object with the same dynamic type as s. The contents of the new object are cleared (not copied!).
  192. Clone is used before the object's contents is copied.
  193. Clone needs not be extended in extensions of Store. However, it can be useful to extend Clone in order to narrow the result type to the actual receiver type (covariance).
  194. Extensions should never make a super call (use the global procedure Clone instead).
  195. Except for performance, equivalent to:
  196.     RETURN Clone(s)
  197. result # NIL
  198. ~result.init
  199. Type(result) = Type(s)
  200. PROCEDURE (s: Store) Init
  201. Initialization of a store. This procedure may be called once only.
  202. Init is called in Internalize, in any copy procedure that an extended store may provide, and in the allocation procedures of store directories.
  203. Init is usually not extended.
  204. ~s.init    20
  205. s.init
  206. PROCEDURE (s: Store) InitDomain (d: Domains.Domain)
  207. A store may be associated with a domain. Such an association may not be changed anymore. Not all stores support domains; for such stores InitDomain can be considered empty, except for the first two of the following precondition checks:
  208. s.init    20
  209. d = NIL  OR  d.init    21
  210. dom(s) = NIL  OR  dom(s) = d    22
  211. s supports domain
  212.     dom(s) = d
  213. PROCEDURE (s: Store) Internalize (VAR rd: Reader)
  214. Reads the contents of s from reader rd. Internalize must read the same (amount of) data as is written by the corresponding Externalize procedure.
  215. Internalize is called internally.
  216. Internalize is extended by various persistent object types, e.g. models, views, and controllers.
  217. Extensions must make a super call first.
  218. ~s.init    20
  219. s.init
  220. PROCEDURE (s: Store) Externalize (VAR wr: Writer)
  221. Write the contents of s to writer wr. Externalize must write the same (amount of) data as is read by the corresponding Internalize procedure.
  222. Externalize ist called internally.
  223. Externalize is extended by various persistent object types, e.g. models, views, and controllers.
  224. Extensions must make a super call first.
  225. s.init    20
  226. TYPE Elem
  227. Interface, Extension
  228. Store readers and writers handle pointers between Elem objects of the same domain such that aliases are handled correctly. This means that elements of a domain can form an arbitrary graph, which can be written and read in again without losing its structure. Element pointers must be written/read using Writer.WriteStore and Reader.ReadStore.
  229. domain-: Domains.Domain
  230. The element's domain, which is initialized by the InitDomain procedure.
  231. TYPE Reader
  232. Reader for Oberon/L values like integers, reals, or sets. A reader contains a Files.File, to which it forwards most operations.
  233. Readers are used in the Store.Internalize procedure.
  234. Readers are not extended.
  235. rider-: Files.Reader
  236. The file rider which links a Reader to a file.
  237. cancelled-: BOOLEAN    valid during a Store.Internalize call
  238. Tells whether the currently executing Internalize has been called by ReadVersion or TurnIntoAlien.
  239. readAlien-: BOOLEAN
  240. Tells whether any alien has been read since the last ConnectTo.
  241. PROCEDURE (VAR rd: Reader) ConnectTo (f: Files.File)
  242. Connect the reader to a file. All the following operations require connected readers, i.e. rd.rider # NIL. This precondition is not checked explicitly, however. After connecting, the reader's position is at the beginning of the file.
  243. ConnectTo is used internally.
  244. s = NIL
  245.     rd.rider = NIL
  246. s # NIL
  247.     (rd.rider # NIL) & (rd.rider.Base() = f)
  248.     rd.Pos() = 0
  249. PROCEDURE (VAR rd: Reader) Pos (): LONGINT
  250. Returns the reader's current position.
  251. 0 <= result <= rd.rider.Base().Length()
  252. PROCEDURE (VAR rd: Reader) SetPos (pos: LONGINT)
  253. Sets the reader's current position to pos.
  254. pos >= 0    20
  255. pos <= rd.rider.Base().Length()    21
  256. rd.Pos() = pos
  257. ~rd.rider.eof
  258. PROCEDURE (VAR rd: Reader) ReadBool (VAR x: BOOLEAN)
  259. Reads a Boolean value.
  260. PROCEDURE (VAR rd: Reader) ReadChar (VAR x: CHAR)
  261. Reads a character (00X..0FFX).
  262. PROCEDURE (VAR rd: Reader) ReadLChar (VAR x: LONGCHAR)
  263. Reads a long character (0000H..0FFFFH).
  264. PROCEDURE (VAR rd: Reader) ReadSInt (VAR x: SHORTINT)
  265. Reads a short integer (-128..127).
  266. PROCEDURE (VAR rd: Reader) ReadInt (VAR x: INTEGER)
  267. Reads an integer (-32768..32767).
  268. PROCEDURE (VAR rd: Reader) ReadLInt (VAR x: LONGINT)
  269. Reads a long integer (-2147483648..2147483647).
  270. PROCEDURE (VAR rd: Reader) ReadReal (VAR x: REAL)
  271. Reads a real (32-bit IEEE number).
  272. PROCEDURE (VAR rd: Reader) ReadLReal (VAR x: LONGREAL)
  273. Reads a long real (64-bit IEEE number).
  274. PROCEDURE (VAR rd: Reader) ReadSet (VAR x: SET)
  275. Reads a set (32 elements).
  276. PROCEDURE (VAR rd: Reader) ReadString (VAR x: ARRAY OF CHAR)
  277. Reads a 00X-terminated string.
  278. LEN(x) > Length(string)    invalid index 
  279. PROCEDURE (VAR rd: Reader) ReadLString (VAR x: ARRAY OF LONGCHAR)
  280. Reads a 0000H-terminated string.
  281. LEN(x) > Length(string)    invalid index 
  282. PROCEDURE (VAR rd: Reader) ReadStore (VAR x: Store)
  283. Reads a store's type, allocates it, and then reads its contents, by calling the store's Internalize procedure. x may also be NIL, or an alien if the store's module cannot be loaded, or if internalization has been cancelled by the Internalize procedure.
  284. If the store is an Elem which has already been read in, a pointer to the same Elem is returned instead of allocating a new one.
  285. empty store on file
  286.     x = NIL
  287. non-empty store on file
  288.     x # NIL
  289.         x IS Alien
  290.             x.cause # 0
  291.             x.type # ""
  292.             x.file # NIL
  293.             x.pos >= 0    beginning of store's data
  294.             x.len >= 0    length of store's data
  295.             alien store contents are on x.file in the range [x.pos .. x.pos + x.len[.
  296.             These data include only the store's contents, not its prefix
  297.         ~(x IS Alien)
  298.             x was read successfully
  299. PROCEDURE (VAR rd: Reader) ReadVersion (min, max: SHORTINT; VAR version: SHORTINT)
  300. Read a version byte and return it in version. If version is not in the specified range [min .. max], the store currently being read is turned into an alien, with cause = alienVersion.
  301. 0 <= min <= max    20
  302. min <= version <= max
  303.     legal version
  304. (version < min) OR (version > max)
  305.     illegal version
  306.     rd.cause = alienVersion
  307.     rd.cancelled
  308.     rd.readAlien
  309. PROCEDURE (VAR rd: Reader) TurnIntoAlien (cause: LONGINT)
  310. A store which is currently being internalized can turn itself into an alien, e.g. if it has read a component store which is an alien.
  311. cause > 0    20
  312. TYPE Writer
  313. Writer for Oberon/L values like integers, reals, or sets. A writer contains a Files.Writer, to which it forwards most operations.
  314. Writers are used in the Stores.Externalize procedure.
  315. Writers are not extended.
  316. rider-: Files.Writer
  317. A file rider which links a Writer to a file.
  318. PROCEDURE (VAR wr: Writer) ConnectTo (f: Files.File)
  319. Connect the writer to a file. All the following operations require connected writers, i.e. wr.rider # NIL. This precondition is not checked explicitly, however. After connecting, the writer's position is at the end of the file.
  320. ConnectTo is used internally.
  321. s = NIL
  322.     wr.rider = NIL
  323. s # NIL
  324.     wr.rider # NIL  &  wr.rider.Base() = f
  325.     wr.Pos() = wr.rider.Base().Length()
  326. PROCEDURE (VAR wr: Writer) Pos (): LONGINT
  327. Returns the writer's current position.
  328. 0 <= result <= wr.rider.Base().Length()
  329. PROCEDURE (VAR wr: Writer) SetPos (pos: LONGINT)
  330. Sets the writer's current position to pos.
  331. pos >= 0    20
  332. pos <= wr.rider.Base().Length()    21
  333. wr.Pos() = pos
  334. PROCEDURE (VAR wr: Writer) WriteBool (x: BOOLEAN)
  335. Writes a Boolean value.
  336. PROCEDURE (VAR wr: Writer) WriteChar (x: CHAR)
  337. Writes a character (00X..0FFX).
  338. PROCEDURE (VAR wr: Writer) WriteLChar (x: LONGCHAR)
  339. Writes a character (0000H..0FFFFH).
  340. PROCEDURE (VAR wr: Writer) WriteSInt (x: SHORTINT)
  341. Writes a short integer (-128..127).
  342. PROCEDURE (VAR wr: Writer) WriteInt (x: INTEGER)
  343. Writes an integer (-32768..32767).
  344. PROCEDURE (VAR wr: Writer) WriteLInt (x: LONGINT)
  345. Writes a long integer (-2147483648..2147483647).
  346. PROCEDURE (VAR wr: Writer) WriteReal (x: REAL)
  347. Writes a real (32-bit IEEE number).
  348. PROCEDURE (VAR wr: Writer) WriteLReal (x: LONGREAL)
  349. Writes a long real (64-bit IEEE number).
  350. PROCEDURE (VAR wr: Writer) WriteSet (x: SET)
  351. Writes a set (32 elements).
  352. PROCEDURE (VAR wr: Writer) WriteString (x: ARRAY OF CHAR)
  353. Writes a 00X-terminated string.
  354. PROCEDURE (VAR wr: Writer) WriteLString (x: ARRAY OF LONGCHAR)
  355. Writes a 0000H-terminated string.
  356. PROCEDURE (VAR wr: Writer) WriteStore (x: Store)
  357. Writes the store's type and then its contents, by calling the store's Externalize procedure. x may also be NIL, or an alien.
  358. PROCEDURE WriteVersion (version: SHORTINT)
  359. Writes a version byte.
  360. version >= 0    20
  361. TYPE Alien, AlienComp, AlienElem, AlienPart, AlienPiece
  362. These auxiliary types are used internally, to handle alien stores.
  363. VAR ReportMsg: PROCEDURE (msg, p0, p1, p2: ARRAY OF CHAR)
  364. Used internally.
  365. PROCEDURE New (type: TypeName): Store
  366. Given the name of a store type in the form "module.record", New returns an object of this type. If the defining module is not yet loaded, New tries to load it. If it cannot be loaded, if there is not enough memory, or if the module doesn't define this type, New returns NIL.
  367. New is called internally.
  368. result = NIL
  369.     type not available
  370. result # NIL
  371.     type available
  372.     result has desired type
  373. PROCEDURE Clone (s: Store): Store
  374. Returns the clone of a store. 
  375. Clone is used internally for the default implementation of Store.Clone, and may be used to implement the Clone procedure of a store extension, instead of performing a super call and then applying a type guard
  376. PROCEDURE GetTypeName (s: Store; VAR type: TypeName)
  377. Returns the name of a store's record type.
  378. PROCEDURE Report (msg, p0, p1, p2: ARRAY OF CHAR)
  379. Used internally.
  380. TextControllers.StdCtrlDesc
  381. TextControllers.ControllerDesc
  382. Containers.ControllerDesc
  383. Controllers.ControllerDesc
  384. Geneva
  385. Documents.ControllerDesc
  386.